/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 *
 */

import { BaseEvent, EventAdditional, EventBody, EventHead, MetricEventType } from './base-event.js';

export enum ObjectEventState {
  NEW = 'new',
  SNAPSHOT = 'snapshot',
  DESTROY = 'destroy',
}

export class ObjectEventAdditional implements EventAdditional {
  objectId: string;
  state: ObjectEventState;
  snapshot?: object;

  constructor(objectId: string, state: ObjectEventState, snapshot?: object) {
    this.objectId = objectId;
    this.state = state;
    this.snapshot = snapshot;
  }
}

export class ObjectEvent extends BaseEvent {
  additional: ObjectEventAdditional;

  constructor(id: string, name: string, description: string, pid: number, tid: string, objectId: string, state: ObjectEventState, snapshot?: object) {
    super(new EventHead(id, name, description, MetricEventType.OBJECT), new EventBody(pid, tid));
    this.additional = new ObjectEventAdditional(objectId, state, snapshot);
    this.body.startTime = Number(process.hrtime.bigint());
  }
}
